import { Component, OnInit } from '@angular/core';
import {HttpClient} from "@angular/common/http";
declare var Swiper: any;

@Component({
  selector: 'app-lunbo',
  templateUrl: './lunbo.component.html',
  styleUrls: ['./lunbo.component.scss']
})
export class LunboComponent implements OnInit {
  // 存放请求来的图片，用来展示轮播
  public imgArr: any = [];
  // 图片下标等于num时显示图片
  public num: any = 0;
  // 清空定时器
  public id: any = 0;
  public key: any;
  constructor(private http: HttpClient) {
  }
  ngOnInit() {
    setTimeout(() => {
      const mySwiper = new Swiper ('.swiper-container', {
        direction: 'horizontal', // 垂直切换选项
        loop: true, // 循环模式选项
        autoplay: true,
        pagination: {
          el: '.swiper-pagination',
          bulletActiveClass: 'my-bullet-active',
        },
      });
    }, 100);
// 请求轮播图数据
    const url = 'http://192.168.2.228:8080/rotation/list';
    this.http.get( url ).subscribe( (result: any) => {
      this.imgArr = result['data']['list'];
    });
  }

}
